/*
 * @FilePath: /flutter_cart/lib/pages/detail_page.dart
 * @Author: Yongchao Wang
 * @Date: 2020-12-05 14:39:31
 * @LastEditors: Yongchao Wang
 * @LastEditTime: 2020-12-10 22:08:21
 */
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../provide/details_info.dart';

class DetailsPages extends StatelessWidget {
  final String goodsId;
  const DetailsPages({Key key, this.goodsId}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Future.delayed(Duration(milliseconds: 200)).then(
        (value) => context.read<DetailsInfoProvide>().getGoodInfo(goodsId));

    return Scaffold(
      appBar: AppBar(
        actions: [],
        leading: IconButton(
          icon: Icon(Icons.arrow_back),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ),
      body: Consumer<DetailsInfoProvide>(
        builder: (BuildContext context, DetailsInfoProvide detailsinfo,
            Widget child) {
          if (detailsinfo.goodInfo != null) {
            return Container(
                child: Column(
              children: [Text(detailsinfo.goodInfo.message)],
            ));
          } else {
            return Text('加载中');
          }
        },
      ),
    );
  }

  Future getGoodsDetail(context) async {
    try {
      var goodinfo = context.watch<DetailsInfoProvide>().goodInfo;
      print(goodinfo);
      return goodinfo;
    } catch (e) {
      return e;
    }
  }
}
